#main.py
import pygame
import sys
from pygame.locals import *
from collections import deque
import random
from point import Point
from graph import Graph

from astar import Astar

if __name__ == '__main__':
    
    WIDTH, HEIGHT = (1000,1000)
    SCREEN_SIZE = (WIDTH, HEIGHT)
    unit = 20
    G = Graph(SCREEN_SIZE, unit)
    start = Point(0,0)
    target = Point(20,19)

    obstacle = []
    for i in range(2,8):
        for j in range(4,6):
            p = Point(i,j)
            obstacle.append(p)
    for i in range(10,14):
        for j in range(40,43):
            p = Point(i,j)
            obstacle.append(p)
    G.set_obstacle(obstacle)
    #check the point if valid
    A = Astar(G,start, target)
    
    path = A.BFS()
    pygame.init()
    screen = pygame.display.set_mode(SCREEN_SIZE)
    pygame.display.set_caption("Astar")
    clock = pygame.time.Clock()
   

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
        
        background_color = (5,125,150)
        screen.fill(background_color)
        key = pygame.key.get_pressed()
        G.draw(screen)
        G.draw_path(screen, path)
        
        pygame.display.update()
        pygame.display.flip()
        clock.tick(10)

